package com.jewel.service.impl;

import com.jewel.mapper.TabBlockMapper;
import com.jewel.mapper.TabItemMapper;
import com.jewel.model.Item;
import com.jewel.pojo.TabBlock;
import com.jewel.pojo.TabItem;
import com.jewel.service.ItemService;
import com.jewel.tools.Tools;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 藏品模块业务类
 * 
 * @author DELL
 *
 * @since 2017.04.27
 */
@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private TabItemMapper tabItemMapper;

    @Autowired
    private TabBlockMapper tabBlockMapper;

    /**
	 * @Title: getItemById
	 * @Description：获取指定id藏品
	 * 
	 * @param itemId
	 * @return Item
	 * @throws：
	 * 
	 */
    @Override
    public Item getItemById(int itemId) {
        Item item = null;

        TabItem tabItem = this.tabItemMapper.selectByPrimaryKey(itemId);
        TabBlock tabBlock = this.tabBlockMapper.selectByPrimaryKey(tabItem.getBlockId());

        if (!Tools.objectIsNullOrNot(tabItem) && !Tools.objectIsNullOrNot(tabBlock)){
        	item = new Item();
        	
            item.setName(tabItem.getTitle());
            item.setDescribes(tabItem.getDescribes());
            item.setBlockName(tabBlock.getName());
        }

        return item;
    }
}
